﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" Inherits="CabinList" Codebehind="CabinList.aspx.cs" %>

<%@ Register TagPrefix="avg" Namespace="Avg.Controls" Assembly="SmartPager" %>
<asp:Content ID="Content3" ContentPlaceHolderID="header" runat="server">
    <a href="/Pages/Boats/CabinItem.aspx?BoatId=<%=BoatId %>" title="New Button"><span
        id="newbutton"></span></a>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
    <div style="margin: 10px 3px 0 3px">
        <h1 style="text-indent: 10px">
            Cabin List</h1>
        <table id="condition">
            <tr>
                <td>
                    <div class="item">
                        <div class="label">
                            Cabin n&#186;:</div>
                        <div class="field">
                            <asp:TextBox ID="txtCabinNumber" runat="server"></asp:TextBox></div>
                    </div>
                </td>
                <td>
                    <asp:LinkButton CssClass="button" ID="btnFind" runat="server" OnClick="btnFind_Click">
                        <span>Search</span>
                    </asp:LinkButton>
                </td>
            </tr>
        </table>
        <div>
            <asp:GridView ID="grv" runat="server" CssClass="grid" AllowSorting="true" AutoGenerateColumns="false"
                DataKeyField="CabinID">
                <Columns>
                    <asp:TemplateField HeaderText="" SortExpression="Name" HeaderStyle-Width="20" HeaderStyle-HorizontalAlign="Center">
                        <ItemTemplate>
                            <%#Container.DataItemIndex+1 %>
                        </ItemTemplate>
                        <HeaderStyle HorizontalAlign="Center" Height="20px"></HeaderStyle>
                        <ItemStyle HorizontalAlign="Center" Height="20px" />
                    </asp:TemplateField>
                    <asp:BoundField HeaderText="Cabin number" DataField="CabinNumber"></asp:BoundField>
                    <asp:BoundField HeaderText="Description" DataField="Description"></asp:BoundField>
                    <asp:BoundField HeaderText="Floor" DataField="Floor"></asp:BoundField>
                    <asp:BoundField HeaderText="Max clients" DataField="MaxGuests"></asp:BoundField>
                    <asp:CheckBoxField HeaderText="For rent" DataField="ForRent"></asp:CheckBoxField>
                    <asp:CheckBoxField HeaderText="Active" DataField="Active"></asp:CheckBoxField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <a href="/Pages/Boats/CabinItem.aspx?BoatId=<%=BoatId %>" id="btnNew">Add</a>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <a href="/Pages/Boats/CabinItem.aspx?BoatId=<%#Eval("BoatId") %>&CabinId=<%#Eval("CabinID") %>"
                                class="btnEdit">Edit</a> |&nbsp;<a cabinid="<%#Eval("CabinID") %>" class="btnDelete">Delete</a>
                        </ItemTemplate>
                        <HeaderStyle Width="70"></HeaderStyle>
                    </asp:TemplateField>
                </Columns>
                <HeaderStyle CssClass="gridheader" />
                <RowStyle CssClass="gridrow" />
                <AlternatingRowStyle CssClass="evenRow" />
            </asp:GridView>
            <avg:SmartPager ID="smartPager" runat="server" Visible="false" NavigatePreviousText="« Previous"
                NavigateNextText="Next »">
            </avg:SmartPager>
        </div>
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            $('#btnNew').button();

            $('.btnDelete').click(function () {
                var result = confirm("Are you sure you want to delete this record?");
                if (result) {

                    var cabinID = $(this).attr("cabinid");
                    var params = "{ CabinID:'" + cabinID + "'}";
                    $.ajax({
                        type: "POST",
                        url: "/Update.asmx/DeleteCabin",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        data: params,
                        success: function (msg) {
                            if (data.d) {
                                // Select provider
                                aTag.parents("tr:first").remove();
                                return false;
                            }
                            else {
                                alert("Delete failed.");
                            }
                        },
                        error: function () {
                            alert("có lỗi");
                            return false;
                        }
                    });
                }
            });
        });
    </script>

</asp:Content>
